//展示用户信息
function showUser() {

    $.ajax({
        url: "/showUser",
        type: "get",
        dataType: "json",
        data: {},
        async: true,
        success: function (result) {
            if (result.code) {
                var json2map = JSON.parse(result.data);
                //控制台显示信息
                $("#nickName").html(json2map.nickname);
                $("#lastTime").html(transformTime(json2map.lastLoginTime));
                $("#lastIp").html(json2map.registerIp);
            } else {
                layer.msg(result.msg, {icon: 5, time: 2000}, function () {
                    location.href = "http://" + window.location.host + "/index.html";
                });
            }
        },
        error: function () {
            layer.alert("系统繁忙,请稍后");
        }
    });
}

showUser();

//时间戳转格式化时间
function transformTime(timestamp) {
    if (timestamp) {
        var time = new Date(timestamp);
        var y = time.getFullYear();
        var M = time.getMonth() + 1;
        var d = time.getDate();
        var h = time.getHours();
        var m = time.getMinutes();
        var s = time.getSeconds();
        return y + '-' + addZero(M) + '-' + addZero(d) + ' ' + addZero(h) + ':' + addZero(m) + ':' + addZero(s);
    } else {
        return '';
    }
}
function addZero(m) {
    return m < 10 ? '0' + m : m;
}